local zhanzhen = fk.CreateSkill{
    name = "XD__zhanzhen"
}
Fk:loadTranslationTable{
    ["XD__zhanzhen"] = "斩阵",
    [":XD__zhanzhen"] = "当你于出牌阶段使用【杀】或【决斗】选择唯一目标时，你可以弃置其一张牌，若你使用的牌为：【决斗】或红色【杀】，此牌对其造成的伤害+1；非红色【杀】，当此【杀】被【闪】抵消时，你失去1点体力。",
}

zhanzhen:addEffect(fk.TargetSpecifying, {
    anim_type = "offensive",
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasSkill(zhanzhen.name) and player.phase == Player.Play and table.contains({"slash","duel"},data.card.trueName) and not data.to:isNude()
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local to = data.to
        local card = room:askToChooseCard(player,{
            target = to,
            flag = "he",
            skill_name = zhanzhen.name,
        })
        room:throwCard(card, zhanzhen.name, to, player)
        data.extra_data = data.extra_data or {}
        if data.card.trueName == "duel" or (data.card.trueName == "slash" and data.card.color == Card.Red) then
            data.extra_data.XD__zhanzhen_damage = data.extra_data.XD__zhanzhen_damage or {}
            table.insert(data.extra_data.XD__zhanzhen_damage, to.id)
        end
        if data.card.trueName == "slash" and data.card.color ~= Card.Red then
            data.extra_data.XD__zhanzhen = data.extra_data.XD__zhanzhen or {}
            data.extra_data.XD__zhanzhen[tostring(player.id)] = data.extra_data.XD__zhanzhen[tostring(player.id)] or {}
            table.insert(data.extra_data.XD__zhanzhen[tostring(player.id)], to.id)
        end
    end,
})

zhanzhen:addEffect(fk.DamageInflicted, {
    can_refresh = function(self, event, target, player, data)
        if target == player and data.card then
            local use_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
            if use_event == nil then return end
            local use = use_event.data
            return use.extra_data and use.extra_data.XD__zhanzhen_damage and table.contains(use.extra_data.XD__zhanzhen_damage, player.id)
        end
    end,
    on_refresh = function(self, event, target, player, data)
        local use_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
        local use = use_event.data
        local num = #table.filter(use.extra_data.XD__zhanzhen_damage,function (element)
            return element == player.id
        end)
        data:changeDamage(num)
    end,
})

zhanzhen:addEffect(fk.CardEffectCancelledOut, {
    anim_type = "negative",
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
        if target == player and data.card.trueName == "slash" and not player.dead then
            local use_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
            if use_event == nil then return false end
            local use = use_event.data
            return use.extra_data and use.extra_data.XD__zhanzhen and use.extra_data.XD__zhanzhen[tostring(player.id)] and table.contains(use.extra_data.XD__zhanzhen[tostring(player.id)], data.to.id)
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:loseHp(player, 1, zhanzhen.name)
    end,
})

return zhanzhen